package com.cll.learn.web.controller;

import com.cll.learn.api.dto.AjaxResult;
import com.cll.learn.api.service.DemoService;
import com.cll.learn.api.service.UserService;
import org.apache.dubbo.config.annotation.DubboReference;
//import org.apache.dubbo.rpc.RpcContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 描述信息:
 *
 * @author CLL
 * @version 1.0
 * @date 2020/10/9 10:47
 */
@RestController
@RequestMapping("/sys/test")
public class TestRestController {

    @DubboReference(interfaceClass = DemoService.class, version = "1.1.0")
    private DemoService demoService;

    @DubboReference(interfaceClass = UserService.class, version = "1.0.0")
    private UserService userService;

    @GetMapping("/sayHello")
    public AjaxResult<String> sayHello(String name, HttpServletRequest request){
        try {
            System.out.println("消费端接收到参数 = " + name);
            String result;
//            RpcContext.getContext().setAttachment()
            String hello = demoService.sayHello(name);
            String user = userService.getUser(name);
            result = "[helloResult] : " + hello + "\t[userResult] : " + user;
            return new AjaxResult<>(200, "操作成功", result);
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult<>(500, "远程调用异常", "");
        }
    }

}